﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Microsoft.Win32;

namespace Nizm0.QOT.Options
{
    public partial class ucMainOptions : UserControl, Library.Objects.IOption
    {
        //private Properties.Settings set = Properties.Settings.Default;
        //Library.Objects.ProjectSettings _project;

        //public MainOptions()
        //{
        //    InitializeComponent();
        //    textBox_DefoultProjectLocalization.Text = Library.Settings.Instance.DefoultProjectLocation;
        //    textBox_MaxRouningProcess.Text = Library.Settings.Instance.MaxRouningProcess.ToString();// Properties.Settings.Default.MaxRouningProcess.ToString();
        //    textBox_ThisProjectLocalization.Text = null;
        //    textBox_LocalizationOfQueryFiles.Text = null;
        //    textBox_OldVersionOfProcedures.Text = null;
        //    textBox_NewVersionOfProcedures.Text = null;
        //    checkBox_WordWrap.Checked = Library.Settings.Instance.ResultWordWrap;// Properties.Settings.Default.ResultWordWrap;
        //}

        public ucMainOptions()//ref Library.Objects.ProjectSettings project)
        {
            InitializeComponent();
            Fill();
        }

        public void Fill()
        {
            //_project = project;
            textBox_DefoultProjectLocalization.Text = Settings.Instance.DefoultProjectLocation;
            textBox_MaxRouningProcess.Text = Settings.Instance.MaxRouningProcess.ToString();// Properties.Settings.Default.MaxRouningProcess.ToString();
            //textBox_OldVersionOfProcedures.Text = Library.Settings.Instance.ProjectSettings.ProjectOldProcedureLocation;
            //textBox_NewVersionOfProcedures.Text = Library.Settings.Instance.ProjectSettings.ProjectNewProcedureLocation;
            checkBox_WordWrap.Checked = Settings.Instance.ResultWordWrap;// Properties.Settings.Default.ResultWordWrap;
            checkBox_Excel.Checked = Settings.Instance.Excel2007;

            comboBox_TextHighlighting.DataSource = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.HighlightingDefinitions;

        }

        private void textBox_MaxRouningProcess_Leave(object sender, EventArgs e)
        {
            //Properties.tmpserver.Default.MaxRouningProcess = Convert.ToInt32(textBox_MaxRouningProcess.Text);
        }

        private void bt_ProjectLocalization_Click(object sender, EventArgs e)
        {
            folderBrowserDialog_Localization.SelectedPath = textBox_DefoultProjectLocalization.Text;// ProjectSettings.ProjectLocation;// Properties.Settings.Default.ProjectLocalization;
            if (folderBrowserDialog_Localization.ShowDialog() == DialogResult.OK)
            {
                textBox_DefoultProjectLocalization.Text = folderBrowserDialog_Localization.SelectedPath;
                //Properties.tmpserver.Default.ProjectLocalization = folderBrowserDialog_Localization.SelectedPath;
            }
        }

        public void SaveSettings()
        {

            Settings.Instance.DefoultProjectLocation = textBox_DefoultProjectLocalization.Text.Trim();
            Settings.Instance.MaxRouningProcess = Convert.ToInt32(textBox_MaxRouningProcess.Text.Trim());
            Settings.Instance.ResultWordWrap = checkBox_WordWrap.Checked;
            Settings.Instance.Excel2007 = checkBox_Excel.Checked;
            Settings.Instance.TextHighlighting = (ICSharpCode.AvalonEdit.Highlighting.IHighlightingDefinition)comboBox_TextHighlighting.SelectedItem;
            Settings.Instance.Save();
        }

        private void bt_Association_Click(object sender, EventArgs e)
        {
            //Create necessary keys
            AssociateFile();
        }

        private static void AssociateFile()
        {
            Settings.Instance.AssociateFile();
        }

        #region IOption
        private string _optionPath = "Main Settings\\Main";
        public string OptionPath
        {
            get
            {
                return _optionPath;
            }
            set
            {
                _optionPath = value;
            }
        }

        private string _optionName = "Main";
        public string OptionName
        {
            get { return _optionName; }
        }

        private bool _optionChange = true;
        public bool OptionChanged
        {
            get { return _optionChange; }
        }

        public bool Save()
        {
            SaveSettings();
            return true;
        }

        public Library.Objects.IOption Show()
        {
            return new ucMainOptions();
        }
        #endregion
    }
}
